//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Utils/Base/Core.h"
#include "Utils/Texture/Image/ImageLoader.h"
#include "Utils/Texture/Image/ImageSaver.h"

namespace Engine
{
namespace Utils
{

	//
	// Image Converter
	//

	struct ImageConverter
	{
	// variables
	private:
		Ptr< UtilsCore >	_core;


	// metadata
	public:
		struct MetaImagePack
		{
			EPixelFormat::type	newFormat;
			float				scale;
			bool				toPOT;
			string				inputDir;		// addition path for input textures
			string				outputDir;		// addition path for output textures
			string_array_t		images;
			///
			MetaImagePack () :
				newFormat( EPixelFormat::type(0) ), scale(1.0f), toPOT(false)
			{}
		};

		struct ImageFrames
		{
			string	idle,
					disabled,
					idle_pressed,
					checked,
					checked_pressed;
		};

		struct MetaImageParts
		{
			EPixelFormat::type		newFormat;
			EImagePartsOrient::type	orient;
			float					scale;
			bool					toPOT;
			string					inputDir;		// addition path for input textures
			string					outputDir;		// addition path for output textures
			string					name;
			vec4					borderColor;
			uvec2					borderSize;
			ImageFrames				frames;
			///
			MetaImageParts () :
				newFormat( EPixelFormat::type(0) ), orient( EImagePartsOrient::AUTO ),
				scale(1.0f), toPOT(false)
			{}
		};

		struct MetaImageConifg
		{
			array< MetaImagePack >	images;
			array< MetaImageParts >	imageParts;
			string					inputDir;
			string					outputDir;
			string					extension;
		};

		static CMetaClass	metaImagePack;
		static CMetaClass	metaImageConfig;
		static CMetaClass	metaImageFrames;
		static CMetaClass	metaImageParts;


		static void InitMetaData ();


	// methods
	public:
		ImageConverter (UtilsCore * core) : _core(core)
		{
			InitMetaData();
		}

		bool LoadConfig (uni_c_string filename, uni_c_string outputPath, bool clearOutputDir);

		static bool Convert (Image &img, EPixelFormat::type newFormat);

	private:
		bool _ConvertImages (const MetaImageConifg &cfg, uni_c_string inputDir, uni_c_string outputDir);
		bool _ConvertParts (const MetaImageConifg &cfg, uni_c_string inputDir, uni_c_string outputDir);
	};


}	// Utils
}	// Engine